#include <bits/stdc++.h>
#define F(i,l,r) for(int i=(l);i<=(r);i++)
#define FF(i,r,l) for(int i=(r);i>=(l);i--)
#define M 200010
//#define maxn
#define ll long long
//#define int long long
#define pb(x) push_back(x)

using namespace std;
//const int mod

int T;
int n,ans;
int a[M];
bool col[M];
void solve(){
    int k=(1<<n)-1;
    
    F(i,1,k){
        int c0=0,c1=0;
        int s=0;
        F(j,1,n){
            col[j]=i&(1<<(j-1));
        }
        F(j,1,n){
            if(col[j]){
                if(a[j]==a[c1]){
                    s+=a[j];
                }
                c1=j;
            }
            else{
                if(a[j]==a[c0]){
                    s+=a[j];
                }
                c0=j;
            }
        }
        if(ans<s){
            ans=s;
        }
    }
    cout<<ans<<'\n';
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        F(i,1,n){
            cin>>a[i];
        }
        if(n<=15){
            solve();
        }
        F(i,1,n)col[i]=0;
    }








    return 0;
}



